package com.zhanggm.student.controller;


import com.zhanggm.student.config.ResponseResult;
import com.zhanggm.student.model.AreaModel;
import com.zhanggm.student.service.IAreaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhanggm
 * @since 2020-10-21
 */
@RestController
@RequestMapping("/area")
public class AreaController {

    @Autowired
    private IAreaService iAreaService;

    /**
     * 根据pid查询地区，展示成树的结构
     * @param pid
     * @return
     */
    @GetMapping("tree")
    public ResponseResult tree(@RequestParam(value = "pid",defaultValue = "1") Integer pid){
        List<AreaModel> areaTree = iAreaService.treelist(pid);
        return ResponseResult.success(areaTree);
    }


    @GetMapping("tree1")
    public ResponseResult tree1(@RequestParam(value = "pid",defaultValue = "1") Integer pid){
        List<AreaModel> areaTree = new ArrayList<>();
        //查询所有地区数据
        List<AreaModel> allList = iAreaService.getAreaAll();
        //查询省的数据
        List<AreaModel> privicelist = iAreaService.getAreaListByPid(allList,pid);
        //遍历省，查询市的数据
        privicelist.forEach(provice->{
            //完成了省的封装
            AreaModel proviceModel = new AreaModel();
        });

        System.out.println(11);
        return ResponseResult.success(areaTree);
    }
    
}
